import Index2 from './index2'; //引入子组件
import { useState, createContext } from 'react';

export const TitleContextInfo = createContext<any>({}); //创建数据源  关键

function Index1() {
  let [titleInfo, setTitleInfo] = useState({ title: '' });
  let [count, setCount] = useState({});
  const changeCom = (value: any) => {
    const a = { title: '标题' + Math.random() };
    // setCount({ ...{} });
    setTitleInfo({ ...a });
    console.debug('修改');
  };
  const titleContextInfo: any = { titleInfo, change: (value: any) => changeCom(value) };
  console.debug('index1');
  return (
    <>
      {
        <button type="button" onClick={() => console.log(titleContextInfo)}>
          打印
        </button>
      }
      <TitleContextInfo.Provider value={titleContextInfo}>
        <Index2 count={count}></Index2>
        <button type="button" onClick={() => changeCom('我是父亲，我修改了公共数据')}>
          父亲
        </button>
      </TitleContextInfo.Provider>
    </>
  );
}
export default Index1;
